﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Cn.Edwon.Biz;
using Cn.Edwon.Spring;
using Cn.Cellula.Biz;
using System.Reflection;
using Cn.Cellula.Model.Content;
using Cn.Cellula.Biz.Port;
using Cn.Cellula.Client;
using Cn.Edwon.Web;
using Cn.Edwon.Web.Support;
using System.Collections.Generic;
using Cn.Cellula.Client.ControlHelper;
namespace Cn.Cellula.Website.Admin.Content.Msg {
    public partial class List : PageSupport {
        IBiz biz = BizFactory.Get<IBiz>();
        protected void Page_Load(object sender, EventArgs e) {
            if (!Page.IsPostBack) {
                InitForm();
                LoadEOList();
            }
        }

        private void LoadEOList() {
            if (!this.Ac.IsLogined) return;
            String hql = " from VMsgEO eo where eo.Reciver='" + this.Actor.ID + "' ";
            if (!String.IsNullOrEmpty(this.txt_Sender.Text)) {
                hql += " and eo.SenderName like '%" + this.txt_Sender.Text + "%' ";
            }
            if (!String.IsNullOrEmpty(this.txt_Content.Text)) {
                hql += " and eo.Content like '%" + this.txt_Content.Text + "%' ";
            }
            if (!String.IsNullOrEmpty(this.txt_Title.Text)) {
                hql += " and eo.Title like '%" + this.txt_Title.Text + "%' ";
            }
            if (!String.IsNullOrEmpty(this.rbl_Read.SelectedValue)) {
                hql += " and eo.IsRead =" + this.rbl_Read.SelectedValue;
            }

            hql += " order by eo.SendDate desc";
            IList<VNewsEditEO> list = biz.Find<VNewsEditEO>(hql);
            this.gvList.DataSource = list;
            this.gvList.DataBind();

        }

        private void InitForm() {
        }

        protected void btn_Query_Click(object sender, EventArgs e) {
            LoadEOList();
        }

        protected void btn_EOAdd_Click(object sender, EventArgs e) {
            Response.Redirect("Send.aspx");
        }


        protected void btn_EODel_Click(object sender, EventArgs e) {
            IList<String> keys = GvHelper.GetSelectedKey(ref this.gvList, ClientBiz.GRIDVIEW_ROW_CHECKBOX_ID);
            if (keys != null && keys.Count > 0) {
                foreach (String k in keys) {
                    biz.Delete<TMsgEO>(keys);
                    BizFactory.Get<ILogBiz>().LogDelete("站内消息", keys.Count, this.Actor, Request);
                }
            } else {
                SiteInfo.Send(Page, TxtDef.ERROR, TxtDef.NoDelSelect);
                return;
            }
            LoadEOList();
        }

        protected void gvList_PageIndexChanging(object sender, GridViewPageEventArgs e) {
            this.gvList.PageIndex = e.NewPageIndex;
            LoadEOList();
        }
    }
}
